package com.example.leetcode.trainingcamp.week8.thursday;

import java.util.ArrayList;
import java.util.List;

/**
 * 给定两个整数 n 和 k，返回范围 [1, n] 中所有可能的 k 个数的组合。
 *
 * 你可以按 任何顺序 返回答案。
 */
public class Test77 {

    private List<List<Integer>> result = new ArrayList<>();

    public List<List<Integer>> combine(int n, int k) {
        int[] ints = new int[n];
        for (int i =0;i<n;i++){
            ints[i] = i+1;
        }
        recursion(ints,0,k,new ArrayList<>());
        return result;
    }


    public void recursion(int[] nums,int count,int k,List<Integer> list){
        if (count == nums.length){
            if (list.size() == k) result.add(new ArrayList<>(list));
            return;
        }
        recursion(nums,count+1,k,list);
        list.add(nums[count]);
        recursion(nums,count+1,k,list);
        list.remove(list.size() -1);
    }
}


class Demo77{
    public static void main(String[] args) {
        int n =4;
        int k = 2;
        Test77 t = new Test77();
        List<List<Integer>> combine = t.combine(n, k);
        for (List<Integer> list:combine) {
            for (int i :list) {
                System.out.print(i+" ");
            }
            System.out.println();
        }
    }
}